using UnityEngine;

class DemoScene : DDScene
{
    public DemoScene()
    {
        AdjustHeight(768);
        DDFont.Default = new DDFont("junegull_fnt");
        DDTextureManager.Instance.PreloadAtlasCocos2d("cat_atlas_plist_1");
        DDTextureManager.Instance.PreloadAtlasCocos2d("cat_atlas_plist_2");
        DDTextureManager.Instance.PreloadAtlasCocos2d("cat_atlas_plist_3");

        var bg = this.AddChild(new DDSlicedSprite("white4x4", this.Size), -1);
        bg.Position = this.Size * DDVector.CenterMiddle;
        bg.Color = DDColor.FromRgbInt(0x7FD3E6);

        var label = this.AddChild(new DDLabel("DD-ENGINE"));
        label.Position = this.Size * DDVector.CenterMiddle;

        label.AddTouchHandler(DDTouchPhase.Began, args =>
        {
            label.StartAction(aa => aa.ColorTo(0.1f, DDColor.Green)
                + aa.ColorTo(0.1f, DDColor.White)
                + aa.Exec(() => DDDirector.Instance.ReplaceScene(new DemoScene(), false))
                );
        });

        var cat = this.AddChild(new DDSprite("cat_00"));
        cat.SetPosition(200, this.Size.Height / 4 * 3);
        cat.AnchorPoint = DDVector.CenterMiddle;

        DDAction action = new DDAnimate("cat_00");
        for (int i = 1; i <= 48; i++)
        {
            action = action + new DDAnimate("cat_" + i.ToString("00"));
        }
        cat.RunAction(new DDRepeatForever(action));

        cat.RunAction(new DDRepeatForever(
            new DDMoveTo(5, this.Size.Width + 200, this.Size.Height / 4 * 3) +
            new DDInstantAction(() => cat.SetPosition(-200, this.Size.Height / 4 * 3))
            ));
    }
}

